/**
 * 
 */
package jMiiEditor.mii.checker;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author CC
 *
 */
public class MiiCheckerProposalSaveAction 
    extends MiiCheckerProposalAbstractAction
        //implements MiiCheckerProposalAction 
{
    private static final long serialVersionUID = 1L;
//    private String message;
    
    public MiiCheckerProposalSaveAction(
            String message
            )
    {
        super(message,true);
    }

//    /* (non-Javadoc)
//     * @see jMiiEditor.mii.checker.MiiCheckerProposal#getMessage()
//     */
//    @Override
//    public String getMessage()
//    {
//        return message;
//    }

    /* (non-Javadoc)
     * @see jMiiEditor.mii.checker.MiiCheckerProposal#getMessageAction()
     */
    @Override
    public String getMessageAction()
    {
        return "Mii.save()";
    }

    @Override
    public String getParameterString()
    {
        return null;
    }

    @Override
    public boolean setParameterString( String newValue )
    {
        return false;
    }

    /* (non-Javadoc)
     * @see jMiiEditor.mii.checker.MiiCheckerProposalAction#applyOn(jMiiEditor.mii.checker.MiiCheckerResult)
     */
    @Override
    public void applyOn( MiiCheckerResult aMiiCheckerResult )
            throws MiiCheckerActionException
    {
        try {
            OutputStream os = aMiiCheckerResult.getMiiCheckerFileObject().getOutputStream();
            aMiiCheckerResult.getMii().save( os );
            os.close();
        }
        catch( NullPointerException e ) {
            throw new MiiCheckerActionException( 
                    "Can't save [" 
                        + aMiiCheckerResult.getMiiCheckerFileObject()
                        + "]",
                        e
                    );
        }
        catch( IOException e ) {
            throw new MiiCheckerActionException( 
                    "Can't save [" 
                        + aMiiCheckerResult.getMiiCheckerFileObject().getDisplayPath()
                        + "]",
                        e
                    );
        }
    }
}
